package com.itheima.autoconfig.template;

import com.baidu.aip.face.AipFace;
import com.itheima.autoconfig.properties.AipFaceProperties;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
/*人脸识别*/
public class AipFaceTemplate {
    @Autowired
    private AipFace client;
    //检测图片中是否包含人脸
    public boolean  detect(String imageUrl) {

        // 调用接口
        String imageType = "URL";
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
        options.put("liveness_control", "LOW");
        // 人脸检测
        JSONObject res = client.detect(imageUrl, imageType, options);
        System.out.println(res.toString(2));
        Integer rescode = (Integer) res.get("error_code");
        return rescode == 0;//返回值是0就说明包含人脸

    }

}

